package cn.edu.sdjzu.nacosproviderservice;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@EnableDiscoveryClient // 启用服务发现客户端 (适用于 Nacos, Consul, Eureka 等)
public class NacosProviderServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(NacosProviderServiceApplication.class, args);
    }
}

@RestController
class HelloController {

    @Value("${server.port}") // 读取当前服务的端口号
    private String serverPort;

    @GetMapping("/hello/{name}")
    public String sayHello(@PathVariable String name) {
        System.out.println("Provider instance on port " + serverPort + " received request.");
        return String.format("[nacos-provider-service:%s] Hello, %s", serverPort, name);
    }
}